//仓库二级联动 局部混淆

import API from "./api";
let mixin = {
  data() {
    return {
      dataStorage: "",
      dataLoctions: ""
    };
  },

  mounted() {
    this.userInfo = this.$store.state.user.userInfo;
    this.initStorage();
  },

  methods: {
    initStorage() {
      let obj = {
        hasLocation: 1
      };
      this.getStorage(obj);
    },

    getStorage(obj) {
      API.getStorage(obj)
        .then(res => {
          if (res.code == 200) {
            let dataSto = res.data;
            this.dataStorage = dataSto.list;
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
        });
    },

    changeStorage(storageNum) {
      let obj = {
        storageNum: storageNum,
        userID: "",
        userName: "",
        b_UserRole: ""
      };
      this.getLoctions(obj);
    },

    getLoctions(obj) {
      API.getLocations(obj)
        .then(res => {
          if (res.code == 200) {
            let dataLoc = res.data;
            this.dataLoctions = dataLoc.list;
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
        });
    }
  }
};

export default mixin;
